package com.zzyl.controller;

import com.zzyl.base.PageResponse;
import com.zzyl.base.ResponseResult;
import com.zzyl.dto.NursingPlanDto;
import com.zzyl.dto.NursingPlanProjectDto;
import com.zzyl.service.NursingPlanService;
import com.zzyl.vo.NursingPlanVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.apache.ibatis.annotations.Delete;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@Api(tags = "护理计划")
@RequestMapping("/nursing")
public class NursingPlanController extends BaseController {

    @Autowired
    NursingPlanService nursingPlanService;

    @GetMapping("/plan")
    @ApiOperation(value = "查询全部护理计划列表")
    public ResponseResult list(){
        List<NursingPlanVo> nursingPlanVo = nursingPlanService.list();
        return success(nursingPlanVo);
    }

    @PostMapping("/plan")
    @ApiOperation(value = "添加护理计划到护理项目")
    public ResponseResult add(
            @ApiParam(value = "传入添加的护理计划id")
            @RequestBody NursingPlanDto projectPlans){
        nursingPlanService.save(projectPlans);
        return success();
    }

    @GetMapping("/plan/search")
    public ResponseResult selectByPage(
            @ApiParam(value = "传入添加的护理计划id") @RequestParam(defaultValue = "10")Integer pageSize,
            @ApiParam(value = "传入添加的护理计划id") @RequestParam(defaultValue = "1")Integer pageNum,
            @ApiParam(value = "传入添加的护理计划id") String name,
            @ApiParam(value = "传入添加的护理计划id") Integer status
    ){
        PageResponse<NursingPlanVo> response = nursingPlanService.selectByPage(pageNum,pageSize,name,status);
        return success(response);
    }

    @GetMapping("/plan/{id}")
    public ResponseResult selectById(@PathVariable Long id){
        NursingPlanVo vo = nursingPlanService.selectById(id);
        return success(vo);
    }

    @PutMapping("/plan/{id}")
    public ResponseResult update(@PathVariable Long id, @RequestBody NursingPlanDto dto){
         nursingPlanService.update(id,dto);
        return success();
    }

    @PutMapping("/{id}/status/{status}")
    public ResponseResult updateStatus(@PathVariable Integer status,@PathVariable Long id){
        nursingPlanService.updateStatus(id,status);
        return success();
    }

    @DeleteMapping("/plan/{id}")
    public ResponseResult delete(@PathVariable Long id){
        nursingPlanService.delete(id);
        return success();
    }
}
